﻿/**
 * Foxit Software Inc.
 * Copyright(C) 2005-2014, all rights reserved.
 * The following code is copyrighted and contains proprietary information
 * and trade secrets of Foxit Software Inc.

 * Description: Annotation list.
 * Author: shaojie zhuo
 */
define(function (require, exports, module) {
    var Annot = require('./Annot.js');
    require('./MarkupAnnot.js');
    require('./LinkAnnot.js');
    require('./AnnotFactory');
    WebPDF.PDFData.PDFAnnotList = function (pageIndex) {
        var _pageIndex = pageIndex,
            _annotList = [];

        /**
         * Get annotation by index.
         * @param {Number} index
         * @returns {WebPDF.Data.PDFAnnot}
         */
        this.getAt = function (index) {
            if (isNaN(index) || index < 0 || index >= _annotList.length)
                return null;
            return _annotList[index];
        };

        /**
         * Get count annotation in current list.
         * @returns {Number}
         */
        this.count = function () {
            return _annotList.length;
        };

        /**
         * Remove all annotations from current list.
         */
        this.removeAll = function () {
            for (var i = 0; i < _annotList.length; i++)
                delete _annotList[i];
            _annotList = [];
        };

        /**
         * Replace annotation by index
         * @param {Number} index index of annotation to replace
         * @param annot {WebPDF.Data.PDFAnnot} annotation to replace
         * @returns {boolean} return true if replacement successfully, otherwise return false.
         */
        this.replace = function (index, annot) {
            if (isNaN(index) || index < 0 || index >= _annotList.length)
                return false;
            _annotList.splice(index, 1, pAnnot);
            return true;
        };

        /**
         * Insert annotation by index.
         * @param index index of annotation to insert.
         * @param annot {WebPDF.Data.PDFAnnot} annotation to insert.
         * @returns {boolean} return true if inserting successfully, otherwise return false.
         */
        this.insert = function (index, annot) {
            if (isNaN(index) || index < -1 || index >= _annotList.length)
                return false;
            _annotList.splice(index, 0, annot);
            return true;
        };

        /**
         * Add annotation to list.
         * @param annot {WebPDF.Data.PDFAnnot} annotation to add.
         * @returns {boolean} return true if adding successfully, otherwise return false.
         */
        this.add = function (annot) {
            _annotList.push(annot);
            return true;
        };

        /**
         * Remove annotation by index
         * @param annotIndex index of annotation to remove.
         * @returns {boolean} return true if removing successfully, otherwise return false.
         */
        this.remove = function (annotIndex) {
            if (isNaN(annotIndex) || annotIndex > _annotList.length || annotIndex < 0) {
                return false;
            }
            delete _annotList[annotIndex];
            _annotList.splice(annotIndex, 1);
            return true;
        };

        /**
         * Get page index of current annotation list.
         * @returns {Number} page index of current annotation list.
         */
        this.getPageIndex = function () {
            return _pageIndex;
        };

        /**
         * Get internal list.
         * @returns {Array}
         */
        this.getAnnotList = function () {
            return _annotList;
        };
    };
    return WebPDF.PDFData.PDFAnnotList;
});